package org.smile.strate.handler;

import javax.servlet.ServletContext;

import org.smile.exception.StrateActionHandlerException;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
/**
 * 从spring窗口中实例化一个action
 * @author strive
 *
 */
public class SpringBeanHandler implements BeanHandler {
	
	public Object getActionBean(String name,ServletContext context) throws StrateActionHandlerException {
		WebApplicationContext webappCtx = WebApplicationContextUtils.getWebApplicationContext(context);
		Object bean=webappCtx.getBean(name);
		if(bean==null){
			throw new StrateActionHandlerException("no bean named "+name+" in spring context");
		}
		return bean;
	}

}
